<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点名</title>
    <style>
        .box {
            width: 400px;
            height: 300px;
            background-color: skyblue;
            margin: 0 auto;
            margin-top: 100px;
            border-radius: 15px;
            text-align: center;
        }

        .box #list {
            width: 200px;
            height: 200px;
            /* border: 1px solid pink; */
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto;
            font-size: 40px;
            color: crimson;
        }

        button {
            width: 80px;
            height: 30px;
            font-size: 16px;
            margin: 0 10px;
            border-radius: 5px;
            border: 1px solid #ccc;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box">
        <div id="list"> ???</div>
        <div class="btn">
            <button id="start">开始</button>
            <button id="stop">停止</button>
        </div>
    </div>
    <script>
        let startBenEle = document.getElementById('start');
        let stopBenEle = document.getElementById('stop');
        let listEle = document.getElementById('list')
        let timer;// 声明成全局变量
        // 获取内容
        let stus = [
            '张一',
            '张二',
            '张三',
            '张四',
            '张五',
            '张六',
            '张七',
            '张八',
            '张九',
            '张十',
            '王一',
            '王二',
            '王三',
            '王四',
            '王五',
            '王六',
            '王七',
            '王八',
            '王九',
            '王十',
        ];

        startBenEle.addEventListener('click', function () {
            // 设置按钮禁用
            this.disabled = true;
            this.innerText = '点名中...';
            timer = setInterval(function () {
                let randIndex = parseInt(stus.length * Math.random());
                listEle.innerText = stus[randIndex];
            }, 10);
        });

        stopBenEle.addEventListener('click', function () {
            // 设置按钮可用
            startBenEle.disabled = false;
            startBenEle.innerText = '开始';
            // 清除上面的定时器动作
            clearInterval(timer);
        });
    </script>
</body>

</html>